﻿@using System.Diagnostics;
@using NewLife.Common;
@using NewLife.Cube.Admin;
@{
    //ViewBag.Title = "服务器信息";
    var fs = Model as List<FileItem>;
    var r = ViewBag.Current as String;
    var clips = ViewBag.Clip as ICollection<FileItem>;
}
<style>
    /*.form-control {
        height: calc(2.4rem + 1px);
    }

    .m-portlet__head {
        height: 5rem;
        border-bottom: 1px solid #ebedf2;
        background-color: white;
        padding: 0 2.2rem;
    }*/
</style>

<div class="kt-portlet">
    <div class="kt-portlet__head">
        <form action="~/Admin/File" id="tool" method="post" class="flex align-items-center">
            <div class="input-group flex align-items-center pt-3">
                @*<span class="input-group-addon">
                        <i class="ace-icon fa fa-check"></i>
                    </span>*@
                <input name="r" type="search" id="r" class="form-control form-control-sm kt-margin-r-5" placeholder="目标路径">
                <span class="input-group-btn kt-margin-r-5">
                    <button type="submit" class="btn btn-primary btn-sm">
                        <span class="glyphicon glyphicon-folder-open icon-on-right bigger-110"></span>
                        打开
                    </button>
                </span>
            @*</div>
            <div class="input-group flex align-items-center">*@
                @*<span class="input-group-addon">
                        <i class="glyphicon glyphicon-file"></i>
                    </span>*@
                <input name="ufile" type="text" id="ufile" value="" class="form-control form-control-sm kt-margin-r-5" placeholder="文件" disabled="disabled" />
                <span class="input-group-btn kt-margin-r-5">
                    <button type="button" class="btn btn-success btn-sm" onclick="$('input[id=file]').click();">
                        <span class="glyphicon glyphicon-cloud-upload icon-on-right bigger-110"></span>
                        选择文件
                    </button>
                </span>
                <span class="input-group-btn kt-margin-r-5">
                    <button type="submit" class="btn btn-success btn-sm" onclick="$('#tool').attr('action', '/Admin/File/Upload');$('#tool').attr('enctype', 'multipart/form-data'); return true;">
                        <span class="glyphicon glyphicon-plus icon-on-right bigger-110"></span>
                        上传
                    </button>
                </span>
            </div>
            <div style="display:none;">
                <input name="file" type="file" id="file" placeholder="上传文件" onchange="$('#ufile').val($('input[id=file]').val());" />
            </div>
            @if (clips.Count > 0)
            {
                <div class="input-group">
                    <span class="input-group-addon">
                        <i class="glyphicon glyphicon-floppy-disk" title="剪切板共有 @clips.Count 项">@clips.Count</i>
                    </span>
                    <span class="input-group-btn">
                        <button type="button" class="btn btn-pink btn-sm" onclick="location.href = '/Admin/File/Paste?r=@r';">
                            <span class="glyphicon glyphicon-floppy-save icon-on-right bigger-110"></span>
                            粘贴
                        </button>
                    </span>
                    <span class="input-group-btn">
                        <button type="button" class="btn btn-gray btn-sm" onclick="location.href = '/Admin/File/Move?r=@r';">
                            <span class="glyphicon glyphicon-floppy-save icon-on-right bigger-110"></span>
                            移动
                        </button>
                    </span>
                    <span class="input-group-btn">
                        <button type="button" class="btn btn-yellow btn-sm" onclick="location.href = '/Admin/File/ClearClipboard?r=@r';">
                            <span class="glyphicon glyphicon-retweet icon-on-right bigger-110"></span>
                            清空
                        </button>
                    </span>
                </div>
            }
        </form>
    </div>

    <div class="kt-portlet__body" style="overflow-x:auto;">
        <table class="table table-bordered table-hover table-striped table-condensed">
            <thead>
                <tr>
                    <th class="text-left"><a href="~/Admin/File?r=@r&sort=name">&nbsp;&nbsp;名称</a></th>
                    <th class="text-right"><a href="~/Admin/File?r=@r&sort=size">大小</a></th>
                    <th class="text-right"><a href="~/Admin/File?r=@r&sort=lastwrite">修改时间</a></th>
                    <th class="text-center">复制</th>
                    <th class="text-center">压缩</th>
                    <th class="text-center">删除</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in fs)
                {
                    <tr>
                        @if (item.Directory)
                        {
                            <td>&nbsp;&nbsp;<a href="~/Admin/File?r=@item.FullName" title="进入目录">@item.Name</a></td>
                        }
                        else
                        {
                            <td>&nbsp;&nbsp;<a href="~/Admin/File/Download?r=@item.FullName" title="下载文件">@item.Name</a></td>
                        }
                        <td class="text-right">@item.Size</td>
                        <td class="text-right">@item.LastWrite.ToFullString("")</td>
                        <td class="text-center">
                            @if (!clips.Any(e => e.FullName == item.FullName))
                            {
                                <a href="~/Admin/File/Copy?r=@r&f=@item.FullName" title="复制到剪切板，然后去目标目录粘贴">复制</a>
                            }
                            else
                            {
                                <a href="~/Admin/File/CancelCopy?r=@r&f=@item.FullName" title="从剪切板移除">取消复制</a>
                            }
                        </td>
                        @if (item.Name.EndsWithIgnoreCase(".zip"))
                        {
                            <td class="text-center"><a href="~/Admin/File/Decompress?r=@item.FullName" title="解压缩到当前目录">解压缩</a></td>
                        }
                        else
                        {
                            <td class="text-center"><a href="~/Admin/File/Compress?r=@item.FullName" title="压缩到当前目录，加上时间后缀">压缩</a></td>
                        }
                        <td class="text-center"><a href="~/Admin/File/Delete?r=@item.FullName" onclick="return confirm('确认删除？');">删除</a></td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>
